import 'package:flutter/material.dart';

class EmptyView extends StatelessWidget {
  EmptyView({Key? key, this.image, this.message, this.reloadAction})
      : super(key: key);

  final VoidCallback? reloadAction;
  final Widget? message;
  final Widget? image;

  Widget _getReloadBtnRow() {
    if (reloadAction != null) {
      return MaterialButton(
          child: Text('重新加载'),
          textColor: Colors.white,
          color: Colors.red,
          elevation: 0,
          minWidth: 100,
          height: 40,
          shape: RoundedRectangleBorder(
              borderRadius: BorderRadius.all(Radius.circular(25))),
          onPressed: reloadAction);
    } else {
      return SizedBox.shrink();
    }
  }

  @override
  Widget build(BuildContext context) {
    return Container(
      width: double.infinity,
      height: double.infinity,
      color: Colors.white,
      child: Column(
        mainAxisAlignment: MainAxisAlignment.center,
        children: [
          image ??
              Image.asset('images/empty/default_empty.png',
                  width: 108, height: 82),
          SizedBox(height: 30),
          message ?? SizedBox.shrink(),
          SizedBox(height: 10),
          _getReloadBtnRow(),
          SizedBox(height: 100)
        ],
      ),
    );
  }
}
